package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.service.IPraiseService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 点赞资源控制器
 */
@RestController
@RequestMapping("/praises")
public class PraiseController {

    @Autowired
    private IPraiseService praiseService;

    /** qiuyanquan
     * 判断用户是否点赞
     * @param travelId
     * @param userId
     * @return
     */
    @GetMapping
    public  Integer getPraiseById( Long travelId, Long userId,int type){
        return praiseService.getPraiseById(travelId,userId,type);
    }

    /**
     * 点赞总数
     * @param travelId
     * @param type
     * @return
     */
    @GetMapping("/nums")
    public  Integer getPraiseNum( Long travelId,int type){
        return praiseService.getPraiseNum(travelId,type);
    }


    //点赞游记
    @PostMapping
    public JSONResult save(Long travelId, Long userId, int type) {
        praiseService.save(travelId,userId,type);
        return new JSONResult();
    }



    //取消游记点赞
    @DeleteMapping("/{id}")
    public JSONResult deleteTravel(@PathVariable Long id) {
        Long userId = UserContext.getCurrentUser().getId();
        praiseService.delete(id,userId,1);
        return new JSONResult();
    }

    //取消攻略点赞
    @DeleteMapping("/{id}/strategy")
    public JSONResult deleteStrategy(@PathVariable Long id) {
        Long userId = UserContext.getCurrentUser().getId();
        praiseService.delete(id,userId,2);
        return new JSONResult();
    }

    //取消日报点赞
    @DeleteMapping("/{id}/news")
    public JSONResult deleteNews(@PathVariable Long id) {
        Long userId = UserContext.getCurrentUser().getId();
        praiseService.delete(id,userId,3);
        return new JSONResult();
    }

    //取消点评点赞
    @DeleteMapping("/{id}/comment")
    public JSONResult deleteComment(@PathVariable Long id) {
        Long userId = UserContext.getCurrentUser().getId();
        praiseService.delete(id,userId,4);
        return new JSONResult();
    }

    @GetMapping("/praiseTravelNum")
    public List<Map> selectPraiseNum(Long[] travelId, int type){
        return praiseService.selectPraiseNum(travelId, type);
    }
}
